#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QIcon icon(":/andriod.png");
    QIcon icon_up(":/up.png");
    QIcon icon_down(":/down.png");
    QIcon icon_right(":/right.png");
    QIcon icon_left(":/left.png");
    ui->pushButton->setIcon(icon);
    ui->pushButton_up->setIcon(icon_up);
    ui->pushButton_down->setIcon(icon_down);
    ui->pushButton_right->setIcon(icon_right);
    ui->pushButton_left->setIcon(icon_left);
    ui->pushButton->setIconSize(QSize(50,50));


    //设置快捷键
    ui->pushButton_up->setShortcut(QKeySequence("ctrl+w"));
    ui->pushButton_down->setShortcut(QKeySequence("ctrl+s"));
    ui->pushButton_right->setShortcut(QKeySequence("ctrl+d"));
    ui->pushButton_left->setShortcut(QKeySequence("ctrl+a"));


    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeat(true);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
}
void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());

}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
}
